package org.ruanjj.randomizedset;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomizedSet2 {
    List<Integer> nums;
    Random rand;

    public RandomizedSet2() {
        nums = new ArrayList<>();
        rand = new Random();
    }

    public boolean insert(int val) {
        if(nums.contains(val)){
            return false;
        }else{
            nums.add(val);
            return true;
        }
    }

    public boolean remove(int val) {
        if(nums.contains(val)){
            nums.remove(Integer.valueOf(val));
            return true;
        }else{
            return false;
        }
    }

    public int getRandom() {
        int randomNum = rand.nextInt(nums.size());
        return nums.get(randomNum);
    }
}
